package com.jd.webapp.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.jd.cms.pojo.Content;
import com.jd.cms.service.ContentService;
import com.jd.common.convention.TTResult;

@Controller
public class ContentController {
	@Autowired
	private ContentService contentService;
	
	@RequestMapping("/content/query/list")
	public @ResponseBody Object getContentsByCid(Content content,int page,int rows){
		try {
			List<Content> list = contentService.getContentsByCid(content, page, rows);
			Map<String,Object> map = new HashMap<String, Object>();
			map.put("total", contentService.getCount(content));
			map.put("rows", list);
			return map;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
	@RequestMapping("/content/save")
	public @ResponseBody Object addContent(Content content){
		try {
			contentService.addContent(content);
			return TTResult.ok();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return TTResult.fail();
	}
}
